package topin.facecat.FaceCat.UI;
import topin.facecat.FaceCat.Service.ADJUSTMENTFACTOR;
import topin.facecat.FaceCat.Service.Security;
import topin.facecat.FaceCat.Service.SecurityData;
import topin.facecat.FaceCat.Service.StockService;
import facecat.topin.core.*;
import java.util.*;
import facecat.topin.div.*;
import facecat.topin.input.*;
import java.text.*;

public class FCChartEx extends FCChart implements FCEventCallBack
{
    public ArrayList<String> m_floatStrs = new ArrayList<String>();

    public ArrayList<Double> m_dates = new ArrayList<Double>();

    public void drawChartCrossLine(FCPaint paint, FCRect clipRect)
    {
        if (m_datas == null || m_datas.size() == 0)
        {
            return;
        }
        FCSize size = getSize();
        int candleDivHeight = getCandleDivHeight();
        int volDivHeight = getVolDivHeight();
        int indDivHeight = getIndDivHeight();
        int crossLineIndex = m_crossStopIndex;
        if (crossLineIndex == -1 || !m_showCrossLine)
        {
            if (m_lastValidIndex != -1)
            {
                crossLineIndex = m_lastValidIndex;
            }
            else
            {
                crossLineIndex = m_lastVisibleIndex;
            }
        }
        if (crossLineIndex < 0 || crossLineIndex > m_datas.size() - 1)
        {
            return;
        }
        if (volDivHeight > 0)
        {
            ArrayList<String> drawTitles = new ArrayList<String>();
            ArrayList<Long> drawColors = new ArrayList<Long>();
            drawTitles.add("VOL ".toString() +
                    FCTran.getValueByDigit(m_datas.get(crossLineIndex).m_volume / m_magnitude, m_volDigit));
            drawColors.add(getTextColor());
            int iLeft = m_leftVScaleWidth + 5;
            for (int i = 0; i < drawTitles.size(); i++)
            {
                FCSize tSize = paint.textSize(drawTitles.get(i), getFont(), -1);
                paint.drawText(
                        drawTitles.get(i), drawColors.get(i), getFont(), new FCRect(iLeft, candleDivHeight + 5, iLeft + tSize.cx, candleDivHeight + 5 + tSize.cy), -1);
                iLeft += tSize.cx + 5;
            }
        }
        //上面显示数据  高开低收
        if (m_cycle.equals("trend"))
        {
            ArrayList<String> drawTitles = new ArrayList<String>();
            ArrayList<Long> drawColors = new ArrayList<Long>();
            if (m_text.length() > 0)
            {
                drawTitles.add(m_text);
                drawColors.add(getTextColor());
            }
            drawColors.add(getTextColor());
            int iLeft = m_leftVScaleWidth + 5;
            for (int i = 0; i < drawTitles.size(); i++)
            {
                FCSize tSize = paint.textSize(drawTitles.get(i), getFont(), -1);
                paint.drawText(drawTitles.get(i), drawColors.get(i), getFont(), new FCRect(iLeft, 5, iLeft + tSize.cx, 5 + tSize.cy), -1);
                iLeft += tSize.cx + 5;
            }
        }
        else
        {
            ArrayList<String> drawTitles = new ArrayList<String>();
            ArrayList<Long> drawColors = new ArrayList<Long>();
            if (m_text.length() > 0)
            {
                drawTitles.add(m_text);
                drawColors.add(getTextColor());
            }
            if (m_mainIndicator.equals("MA"))
            {
                if (m_ma5.size() > 0)
                {
                    drawTitles.add("MA5 ".toString() +
                            FCTran.getValueByDigit(m_ma5.get(crossLineIndex), m_candleDigit));
                }
                else
                {
                    drawTitles.add("MA5");
                }
                drawColors.add(m_indicatorColors.get(0));
                if (m_ma10.size() > 0)
                {
                    drawTitles.add("MA10 ".toString() +
                            FCTran.getValueByDigit(m_ma10.get(crossLineIndex), m_candleDigit));
                }
                else
                {
                    drawTitles.add("MA10");
                }
                drawColors.add(m_indicatorColors.get(1));
                if (m_ma20.size() > 0)
                {
                    drawTitles.add("MA20 ".toString() +
                            FCTran.getValueByDigit(m_ma20.get(crossLineIndex), m_candleDigit));
                }
                else
                {
                    drawTitles.add("MA20");
                }
                drawColors.add(m_indicatorColors.get(2));
                if (m_ma30.size() > 0)
                {
                    drawTitles.add("MA30 ".toString() +
                            FCTran.getValueByDigit(m_ma30.get(crossLineIndex), m_candleDigit));
                }
                else
                {
                    drawTitles.add("MA30");
                }
                drawColors.add(m_indicatorColors.get(5));
                if (m_ma120.size() > 0)
                {
                    drawTitles.add("MA120 ".toString() +
                            FCTran.getValueByDigit(m_ma120.get(crossLineIndex), m_candleDigit));
                }
                else
                {
                    drawTitles.add("MA120");
                }
                drawColors.add(m_indicatorColors.get(4));
                if (m_ma250.size() > 0)
                {
                    drawTitles.add("MA250 ".toString() +
                            FCTran.getValueByDigit(m_ma250.get(crossLineIndex), m_candleDigit));
                }
                else
                {
                    drawTitles.add("MA250");
                }
                drawColors.add(m_indicatorColors.get(3));
            }
            int iLeft = m_leftVScaleWidth + 5;
            for (int i = 0; i < drawTitles.size(); i++)
            {
                FCSize tSize = paint.textSize(drawTitles.get(i), getFont(), -1);
                paint.drawText(drawTitles.get(i), drawColors.get(i), getFont(), new FCRect(iLeft, 5, iLeft + tSize.cx, 5 + tSize.cy), -1);
                if (i == 0 && m_text.length() > 0)
                {
                    int midY = 13;
                    FCSize cSize = paint.textSize(m_subComboBox.getText(), m_subComboBox.getFont(), -1);
                    int sWidth = cSize.cx + 25;
                    FCRect subBounds = new FCRect(iLeft + tSize.cx + 8, midY - 10, iLeft + tSize.cx + 8 + sWidth, midY + 10);
                    m_subComboBox.setBounds(subBounds);
                    iLeft += sWidth + 16;
                }
                iLeft += tSize.cx + 5;
            }
        }
        if (indDivHeight > 0)
        {
            ArrayList<String> drawTitles = new ArrayList<String>();
            ArrayList<Long> drawColors = new ArrayList<Long>();
            if (m_showIndicator.equals("MACD"))
            {
                if (m_alldifarr.size() > 0)
                {
                    drawTitles.add("DIF ".toString() +
                            FCTran.getValueByDigit(m_alldifarr.get(crossLineIndex), m_indDigit));
                }
                else
                {
                    drawTitles.add("DIF");
                }
                drawColors.add(m_indicatorColors.get(0));
                if (m_alldeaarr.size() > 0)
                {
                    drawTitles.add("DEA ".toString() +
                            FCTran.getValueByDigit(m_alldeaarr.get(crossLineIndex), m_indDigit));
                }
                else
                {
                    drawTitles.add("DEA");
                }
                drawColors.add(m_indicatorColors.get(1));
                if (m_allmacdarr.size() > 0)
                {
                    drawTitles.add("MACD ".toString() +
                            FCTran.getValueByDigit(m_allmacdarr.get(crossLineIndex), m_indDigit));
                }
                else
                {
                    drawTitles.add("MACD");
                }
                drawColors.add(m_indicatorColors.get(4));
            }
            else if (m_showIndicator.equals("KDJ"))
            {
                if (m_kdjK.size() > 0)
                {
                    drawTitles.add("K ".toString() +
                            FCTran.getValueByDigit(m_kdjK.get(crossLineIndex), m_indDigit));
                }
                else
                {
                    drawTitles.add("K");
                }
                drawColors.add(m_indicatorColors.get(0));
                if (m_kdjD.size() > 0)
                {
                    drawTitles.add("D ".toString() +
                            FCTran.getValueByDigit(m_kdjD.get(crossLineIndex), m_indDigit));
                }
                else
                {
                    drawTitles.add("D");
                }
                drawColors.add(m_indicatorColors.get(1));
                if (m_kdjJ.size() > 0)
                {
                    drawTitles.add("J ".toString() +
                            FCTran.getValueByDigit(m_kdjJ.get(crossLineIndex), m_indDigit));
                }
                else
                {
                    drawTitles.add("J");
                }
                drawColors.add(m_indicatorColors.get(2));
            }
            int iLeft = m_leftVScaleWidth + 5;
            for (int i = 0; i < drawTitles.size(); i++)
            {
                FCSize tSize = paint.textSize(drawTitles.get(i), getFont(), -1);
                paint.drawText(drawTitles.get(i), drawColors.get(i), getFont(), new FCRect(iLeft,
                        candleDivHeight + volDivHeight + 5, iLeft + tSize.cx,
                        candleDivHeight + volDivHeight + 5 + tSize.cy), -1);
                iLeft += tSize.cx + 5;
            }
        }
        if (m_showCrossLine)
        {
            String rightText = "";
            if (m_touchPosition.y < candleDivHeight)
            {
                rightText = FCTran.getValueByDigit(getChartValue(m_touchPosition)
                        , m_candleDigit);
            }
            else if (m_touchPosition.y > candleDivHeight &&
                    m_touchPosition.y < candleDivHeight + volDivHeight)
            {
                rightText = FCTran.getValueByDigit(getChartValue(m_touchPosition) / m_magnitude
                        , m_volDigit);
            }
            else if (m_touchPosition.y > candleDivHeight + volDivHeight &&
                    m_touchPosition.y < candleDivHeight + volDivHeight + indDivHeight)
            {
                rightText = FCTran.getValueByDigit(getChartValue(m_touchPosition)
                        , m_indDigit);
            }

            int drawY = m_touchPosition.y;
            if (drawY > size.cy)
            {
                drawY = size.cy;
            }
            FCSize tSize2 = paint.textSize(rightText, getFont(), -1);
            if (m_leftVScaleWidth > 0)
            {
                paint.fillRect(m_crossTipColor, m_leftVScaleWidth - tSize2.cx, drawY - tSize2.cy / 2 - 4,
                        m_leftVScaleWidth, drawY + tSize2.cy / 2 + 3);
                paint.drawText(rightText, getTextColor(), getFont(),
                        new FCRect(m_leftVScaleWidth - tSize2.cx, drawY - tSize2.cy / 2, m_leftVScaleWidth, drawY + tSize2.cy / 2), -1);
            }
            if (m_rightVScaleWidth > 0)
            {
                paint.fillRect(m_crossTipColor, size.cx - m_rightVScaleWidth, drawY - tSize2.cy / 2 - 4,
                        size.cx - m_rightVScaleWidth + tSize2.cx, drawY + tSize2.cy / 2 + 3);
                paint.drawText(rightText, getTextColor(), getFont(),
                        new FCRect(size.cx - m_rightVScaleWidth, drawY - tSize2.cy / 2, size.cx - m_rightVScaleWidth + tSize2.cx, drawY + tSize2.cy / 2), -1);
            }
            //绘制十字线
            int drawX = getChartX(m_crossStopIndex);
            if (m_targetOldX == 0 && m_targetOldX2 == 0)
            {
                drawX = m_touchPosition.x;
            }
            if (drawX < m_leftVScaleWidth)
            {
                drawX = m_leftVScaleWidth;
            }
            if (drawX > size.cx - m_rightVScaleWidth)
            {
                drawX = size.cx - m_rightVScaleWidth;
            }
            if (m_showCrossLine)
            {
                paint.drawLine(m_crossLineColor, m_lineWidthChart, 0,
                        m_leftVScaleWidth, drawY, size.cx - m_rightVScaleWidth, drawY);
                paint.drawLine(m_crossLineColor, m_lineWidthChart, 0, drawX, 0,
                        drawX, getHeight() - m_hScaleHeight);
            }
            int cRealIndex = getChartIndexReal(getTouchPoint());
            if ((cRealIndex != -1 && cRealIndex > m_firstVisibleIndex) && (cRealIndex < m_datas.size() || cRealIndex - m_firstVisibleIndex < m_dates.size()))
            {
                double dateNum = 0;
                if (m_dates.size() > 0 && cRealIndex - m_firstVisibleIndex < m_dates.size())
                {
                    dateNum = m_dates.get(cRealIndex - m_firstVisibleIndex);
                }
                else
                {
                    dateNum = m_datas.get(cRealIndex).m_date;
                }
                String xText = new Double(dateNum).toString();
                Calendar dt = FCTran.numToDate(dateNum);
                if (m_cycle.equals("day"))
                {
                    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
                    xText = format.format(dt.getTime()) + ",";
                    xText += getWeekStr(StockService.dayOfWeek(dt.get(Calendar.YEAR), dt.get(Calendar.MONTH) + 1, dt.get(Calendar.DAY_OF_MONTH)));
                }
                else if (m_cycle.equals("minute"))
                {
                    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm");
                    xText = format.format(dt.getTime()) + ",";
                    xText += getWeekStr(StockService.dayOfWeek(dt.get(Calendar.YEAR), dt.get(Calendar.MONTH) + 1, dt.get(Calendar.DAY_OF_MONTH)));
                }
                else
                {
                    if (m_hScaleFormat.length() > 0)
                    {
                        SimpleDateFormat format = new SimpleDateFormat(m_hScaleFormat);
                        xText = format.format(dt.getTime());
                    }
                    else
                    {
                        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                        xText =format.format(dt.getTime());
                    }
                }
                FCSize xSize = paint.textSize(xText, getFont(), -1);
                int bTop = getHeight() - m_hScaleHeight;
                paint.fillRect(
                        m_crossTipColor,
                        drawX - xSize.cx / 2 - 2,
                        bTop,
                        drawX + xSize.cx / 2 + 2,
                        bTop + xSize.cy + 6);
                paint.drawText(xText, getTextColor(), getFont(), new FCRect(drawX - xSize.cx / 2,
                        bTop + 3, drawX + xSize.cx / 2,
                        bTop + 3 + xSize.cy), -1);
            }
        }
    }

    public ADJUSTMENTFACTOR m_touchFactor = null;
    public int m_sIndex = -1;

    public void drawChartScale(FCPaint paint, FCRect clipRect)
    {
        m_dates.clear();
        m_touchFactor = null;
        m_sIndex = -1;
        FCSize size = getSize();
        int candleDivHeight = getCandleDivHeight();
        int volDivHeight = getVolDivHeight();
        int indDivHeight = getIndDivHeight();
        if (m_leftVScaleWidth > 0)
        {
            paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                    m_leftVScaleWidth, 0, m_leftVScaleWidth,
                    size.cy);
        }
        if (m_rightVScaleWidth > 0)
        {
            paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                    size.cx - m_rightVScaleWidth, 0, size.cx - m_rightVScaleWidth,
                    size.cy);
        }
        if (m_hScaleHeight > 0)
        {
            paint.drawLine(m_scaleColor, m_lineWidthChart, 0, 0,
                    getHeight() - m_hScaleHeight, size.cx, getHeight() - m_hScaleHeight);
        }
        if (volDivHeight > 0)
        {
            paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                    0, candleDivHeight, size.cx, candleDivHeight);
        }
        if (indDivHeight > 0)
        {
            paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                    m_leftVScaleWidth, candleDivHeight + volDivHeight,
                    size.cx - m_rightVScaleWidth,
                    candleDivHeight + volDivHeight);
        }
        if (m_datas.size() > 0)
        {
            FCPoint topPoint = new FCPoint(0, 20);
            FCPoint bottomPoint = new FCPoint(0, candleDivHeight - 10);
            double candleMax = getChartValue(topPoint);
            double candleMin = getChartValue(bottomPoint);
            chartGridScale(candleMin, candleMax, (candleDivHeight - m_candlePaddingTop - m_candlePaddingBottom) / 2,
                    m_vScaleDistance, m_vScaleDistance / 2,
                    (candleDivHeight - m_candlePaddingTop - m_candlePaddingBottom) / m_vScaleDistance);
            if (m_gridStep > 0)
            {
                ArrayList<Double> drawValues = new ArrayList<Double>();
                boolean isTrend = m_cycle.equals("trend");
                double firstOpen = 0;
                if (isTrend)
                {
                    if (m_firstOpen != 0)
                    {
                        firstOpen = m_firstOpen;
                    }
                    else
                    {
                        firstOpen = m_datas.get(m_firstVisibleIndex).m_close;
                    }
                    if (firstOpen == 0)
                    {
                        firstOpen = candleMin;
                    }
                    double subValue = (candleMax - candleMin);
                    int count = (candleDivHeight -
                            m_candlePaddingTop -
                            m_candlePaddingBottom) /
                            m_vScaleDistance;
                    if (count > 0)
                    {
                        subValue /= count;
                    }
                    double start = firstOpen;
                    while (start < candleMax)
                    {
                        start += subValue;
                        if (start <= candleMax)
                        {
                            drawValues.add(start);
                        }
                    }
                    start = firstOpen;
                    while (start > candleMin)
                    {
                        start -= subValue;
                        if (start >= candleMin)
                        {
                            drawValues.add(start);
                        }
                    }
                }
                else
                {
                    double start = 0;
                    if (candleMin >= 0)
                    {
                        while (start + m_gridStep < candleMin)
                        {
                            start += m_gridStep;
                        }
                    }
                    else
                    {
                        while (start - m_gridStep > candleMin)
                        {
                            start -= m_gridStep;
                        }
                    }

                    while (start <= candleMax)
                    {
                        if (start > candleMin)
                        {
                            drawValues.add(start);
                        }
                        start += m_gridStep;
                    }
                }
                drawValues.add(firstOpen);
                for (int i = 0; i < drawValues.size(); i++)
                {
                    double start = drawValues.get(i);
                    int hAxisY = getChartY(0, start);
                    if (hAxisY < 1 || hAxisY >= candleDivHeight)
                    {
                        continue;
                    }
                    if (m_cycle.equals("trend") && start == firstOpen)
                    {
                        paint.drawLine(m_scaleColor, 1, 0,
                                m_leftVScaleWidth, hAxisY,
                                size.cx - m_rightVScaleWidth, hAxisY);
                    }
                    else
                    {
                        paint.drawLine(m_gridColor, m_lineWidthChart, 0,
                                m_leftVScaleWidth, hAxisY,
                                size.cx - m_rightVScaleWidth, hAxisY);
                    }
                    paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                            m_leftVScaleWidth - 8, hAxisY, m_leftVScaleWidth, hAxisY);
                    paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                            size.cx - m_rightVScaleWidth, hAxisY,
                            size.cx - m_rightVScaleWidth + 8, hAxisY);

                    String drawText = FCTran.getValueByDigit(start, m_candleDigit);

                    FCSize tSize = paint.textSize(drawText, getFont(), -1);
                    if (isTrend)
                    {
                        double diffRange = ((start - firstOpen) / firstOpen * 100);
                        String diffRangeStr = FCTran.getValueByDigit(diffRange, 2) + "%".toString();
                        FCSize dSize = paint.textSize(diffRangeStr, getFont(), -1);
                        if (diffRange > 0)
                        {
                            paint.drawText(diffRangeStr, FCColor.rgb(255, 82, 82), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                            hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + dSize.cx,
                                            hAxisY + tSize.cy / 2), -1);
                            FCDraw.drawUnderLineNum(paint, start, m_candleDigit, getFont(), FCColor.rgb(255, 82, 82), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                        }
                        else if (diffRange < 0)
                        {
                            paint.drawText(diffRangeStr, FCColor.rgb(46, 255, 50), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                            hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + dSize.cx,
                                            hAxisY + tSize.cy / 2), -1);
                            FCDraw.drawUnderLineNum(paint, start, m_candleDigit, getFont(), FCColor.rgb(46, 255, 50), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                        }
                        else
                        {
                            paint.drawText(diffRangeStr, m_textColor, getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                            hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + dSize.cx,
                                            hAxisY + tSize.cy / 2), -1);
                            FCDraw.drawUnderLineNum(paint, start, m_candleDigit, getFont(), m_textColor, false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                        }
                    }
                    else
                    {
                        int digit = m_candleDigit;
                        if (m_candleMax > 1000)
                        {
                            digit = 0;
                        }
                        if (MyColor.m_style == 0)
                        {
                            FCDraw.drawUnderLineNum(paint, start, digit, getFont(), FCColor.rgb(233, 153, 46), false, size.cx - m_rightVScaleWidth + 12,
                                    hAxisY - tSize.cy / 2 - 1);
                        }
                        else
                        {
                            FCDraw.drawUnderLineNum(paint, start, digit, getFont(), getTextColor(), false, size.cx - m_rightVScaleWidth + 12,
                                    hAxisY - tSize.cy / 2 - 1);
                        }
                        if (MyColor.m_style == 0)
                        {
                            FCDraw.drawUnderLineNum(paint, start, digit, getFont(), FCColor.rgb(233, 153, 46), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                        }
                        else
                        {
                            FCDraw.drawUnderLineNum(paint, start, digit, getFont(), getTextColor(), false, m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2 - 1);
                        }
                    }
                }
            }
            topPoint = new FCPoint(0, candleDivHeight + 10);
            bottomPoint = new FCPoint(0, candleDivHeight + volDivHeight - 10);
            double volMax = getChartValue(topPoint);
            double volMin = getChartValue(bottomPoint);
            chartGridScale(volMin, volMax, (volDivHeight - m_volPaddingTop - m_volPaddingBottom) / 2,
                    m_vScaleDistance, m_vScaleDistance / 2,
                    (volDivHeight - m_volPaddingTop - m_volPaddingBottom) / m_vScaleDistance);
            if (m_gridStep > 0)
            {
                double start = 0;
                if (volMin >= 0)
                {
                    while (start + m_gridStep < volMin)
                    {
                        start += m_gridStep;
                    }
                }
                else
                {
                    while (start - m_gridStep > volMin)
                    {
                        start -= m_gridStep;
                    }
                }
                while (start <= volMax)
                {
                    if (start > volMin)
                    {
                        int hAxisY = getChartY(1, start);
                        if (hAxisY < candleDivHeight ||
                                hAxisY > candleDivHeight + volDivHeight)
                        {
                            start += m_gridStep;
                            continue;
                        }
                        paint.drawLine(m_gridColor, m_lineWidthChart, 0, m_leftVScaleWidth,
                                hAxisY, size.cx - m_rightVScaleWidth, hAxisY);
                        paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                                m_leftVScaleWidth - 8, hAxisY, m_leftVScaleWidth, hAxisY);
                        paint.drawLine(m_scaleColor, m_lineWidthChart, 0, size.cx - m_rightVScaleWidth,
                                hAxisY, size.cx - m_rightVScaleWidth + 8, hAxisY);
                        String drawText =
                                FCTran.getValueByDigit(start / m_magnitude, m_volDigit);
                        FCSize tSize = paint.textSize(drawText, getFont(), -1);
                        if (MyColor.m_style == 0)
                        {
                            paint.drawText(drawText, FCColor.rgb(233, 153, 46), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                            hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + tSize.cx,
                                            hAxisY + tSize.cy / 2), -1);
                            paint.drawText(drawText, FCColor.rgb(233, 153, 46), getFont(),
                                    new FCRect(m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2, m_leftVScaleWidth - 10, hAxisY + tSize.cy / 2), -1);
                        }
                        else
                        {
                            paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                            hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + tSize.cx,
                                            hAxisY + tSize.cy / 2), -1);
                            paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2, m_leftVScaleWidth - 10, hAxisY + tSize.cy / 2), -1);
                        }
                    }
                    start += m_gridStep;
                }
            }
            if (indDivHeight > 0)
            {
                topPoint = new FCPoint(0, candleDivHeight + volDivHeight + 10);
                bottomPoint =
                        new FCPoint(0, candleDivHeight + volDivHeight + indDivHeight - 10);
                double indMax = getChartValue(topPoint);
                double indMin = getChartValue(bottomPoint);
                chartGridScale(indMin, indMax, (indDivHeight - m_indPaddingTop - m_indPaddingBottom) / 2,
                        m_vScaleDistance, m_vScaleDistance / 2,
                        (indDivHeight - m_indPaddingTop - m_indPaddingBottom) / m_vScaleDistance);
                if (m_gridStep > 0)
                {
                    double start = 0;
                    if (indMin >= 0)
                    {
                        while (start + m_gridStep < indMin)
                        {
                            start += m_gridStep;
                        }
                    }
                    else
                    {
                        while (start - m_gridStep > indMin)
                        {
                            start -= m_gridStep;
                        }
                    }

                    while (start <= indMax)
                    {
                        if (start > indMin)
                        {
                            int hAxisY = getChartY(2, start);
                            if (hAxisY < candleDivHeight + volDivHeight ||
                                    hAxisY > candleDivHeight + volDivHeight + indDivHeight)
                            {
                                start += m_gridStep;
                                continue;
                            }
                            paint.drawLine(m_gridColor, m_lineWidthChart, 0, m_leftVScaleWidth, hAxisY, size.cx - m_rightVScaleWidth, hAxisY);
                            paint.drawLine(m_scaleColor, m_lineWidthChart, 0, m_leftVScaleWidth - 8, hAxisY, m_leftVScaleWidth, hAxisY);
                            paint.drawLine(m_scaleColor, m_lineWidthChart, 0,
                                    size.cx - m_rightVScaleWidth, hAxisY, size.cx - m_rightVScaleWidth + 8, hAxisY);
                            String drawText = FCTran.getValueByDigit(start, m_indDigit);
                            FCSize tSize = paint.textSize(drawText, getFont(), -1);
                            paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(size.cx - m_rightVScaleWidth + 10,
                                            hAxisY - tSize.cy / 2, size.cx - m_rightVScaleWidth + 10 + tSize.cx,
                                            hAxisY + tSize.cy / 2), -1);
                            paint.drawText(drawText, getTextColor(), getFont(),
                                    new FCRect(m_leftVScaleWidth - tSize.cx - 10, hAxisY - tSize.cy / 2, m_leftVScaleWidth - 10, hAxisY + tSize.cy / 2), -1);
                        }
                        start += m_gridStep;
                    }
                }
            }
        }
        if (m_datas.size() > 0 && m_hScaleHeight > 0)
        {
            long newScaleColor = getTextColor();
            if (MyColor.m_style == 0)
            {
                newScaleColor = FCColor.rgb(233, 153, 46);
            }
            if (m_cycle.equals("trend"))
            {
                ArrayList<Double> times = new ArrayList<Double>();
                if (getWidth() < 600)
                {
                    times.add(FCTran.getDateNum(1970, 1, 1, 10, 30, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 11, 30, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 14, 0, 0, 0));
                }
                else
                {
                    times.add(FCTran.getDateNum(1970, 1, 1, 10, 0, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 10, 30, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 11, 0, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 11, 30, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 13, 30, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 14, 0, 0, 0));
                    times.add(FCTran.getDateNum(1970, 1, 1, 14, 30, 0, 0));
                }
                int bBottom = getHeight();
                String leftStr = "9:30";
                FCSize leftSize = paint.textSize(leftStr, getFont(), -1);
                String rightStr = "15:00";
                FCSize rightSize = paint.textSize(rightStr, getFont(), -1);
                paint.drawText(leftStr, newScaleColor, getFont(), new FCRect(m_leftVScaleWidth + 5, bBottom - (m_hScaleHeight + leftSize.cy) / 2, m_leftVScaleWidth + leftSize.cx + 5, bBottom - (m_hScaleHeight + leftSize.cy) / 2), -1);
                paint.drawText(rightStr, newScaleColor, getFont(), new FCRect(size.cx - m_rightVScaleWidth - rightSize.cx - 5, bBottom - (m_hScaleHeight + leftSize.cy) / 2, size.cx - m_rightVScaleWidth - 5, bBottom - (m_hScaleHeight + leftSize.cy) / 2), -1);
                for (int i = m_firstVisibleIndex; i <= m_lastVisibleIndex; i++)
                {
                    double dateNum = m_datas.get(i).m_date;
                    Calendar dt = FCTran.numToDate(dateNum);
                    int hour = dt.get(Calendar.HOUR_OF_DAY);
                    int minute = dt.get(Calendar.MINUTE);
                    double timeNum = FCTran.getDateNum(1970, 1, 1, dt.get(Calendar.HOUR_OF_DAY), dt.get(Calendar.MINUTE), 0, 0);
                    if (times.contains(timeNum))
                    {
                        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                        String xText = format.format(dt.getTime());
                        FCSize tSize = paint.textSize(xText, getFont(), -1);
                        int x = getChartX(i);
                        int dx = x - tSize.cx / 2;
                        paint.drawLine(m_scaleColor, m_lineWidthChart, 0, x, bBottom - m_hScaleHeight, x, bBottom - m_hScaleHeight + 5);
                        paint.drawText(xText, newScaleColor, getFont(), new FCRect(dx, bBottom - (m_hScaleHeight + leftSize.cy) / 2, dx + tSize.cx, bBottom - (m_hScaleHeight + leftSize.cy) / 2), -1);
                        paint.drawLine(m_gridColor, 1, 0, x, 0, x, bBottom - m_hScaleHeight);
                    }
                }
            }
            else
            {
                double dLeft = m_leftVScaleWidth;
                if (m_cycle.equals("day"))
                {
                    if (StockService.m_factors.containsKey(m_myChart.m_code))
                    {
                        ArrayList<ADJUSTMENTFACTOR> factor = StockService.m_factors.get(m_myChart.m_code);
                        int startIndex = m_firstVisibleIndex;
                        String txtSignal = "S";
                        FCFont sFont = new FCFont("Default", 10.5f, false, false, false);
                        FCSize sSize = paint.textSize(txtSignal, sFont, -1);
                        FCPoint mp = getTouchPoint();
                        for (int i = 0; i < factor.size(); i++)
                        {
                            double date = factor.get(i).dwDate;
                            int drawIndex = -1;
                            for (int j = startIndex; j <= m_lastVisibleIndex; j++)
                            {
                                double lastDate = 0;
                                double nextDate = 0;
                                if (j > 0)
                                {
                                    lastDate = m_datas.get(j - 1).m_date;
                                }
                                if (j < m_datas.size() - 1)
                                {
                                    nextDate = m_datas.get(j + 1).m_date;
                                }
                                if (date == m_datas.get(j).m_date || (date > lastDate && date < nextDate))
                                {
                                    drawIndex = j;
                                    startIndex = j + 1;
                                    break;
                                }
                            }
                            if (drawIndex != -1)
                            {
                                int x = getChartX(drawIndex);
                                FCDraw.drawText(paint, txtSignal, FCColor.rgb(255, 0, 0), sFont, x - sSize.cx / 2, candleDivHeight - sSize.cy);
                                if (mp.x >= x - sSize.cx / 2 && mp.x <= x + sSize.cx / 2 && mp.y >= candleDivHeight - sSize.cy && mp.y <= candleDivHeight)
                                {
                                    m_touchFactor = factor.get(i);
                                    m_sIndex = drawIndex;
                                }
                            }
                        }
                    }
                }
                if (m_cycle.equals("day"))
                {
                    int fIndex = m_firstVisibleIndex;
                    int lIndex = m_lastVisibleIndex;
                    if (lIndex >= fIndex)
                    {
                        ArrayList<Double> dates = new ArrayList<Double>();
                        for (int d = fIndex; d <= lIndex; d++)
                        {
                            dates.add(m_datas.get(d).m_date);
                        }
                        int drawLeft = m_leftVScaleWidth; //左侧起画点
                        int i = fIndex; //开始索引
                        int lastYear = 0; //缓存年份，用于判断是否换年
                        ArrayList<Integer> drawYearsCache = new ArrayList<Integer>(); //实际绘制到图形上的年份文字
                        int lastTextRight = 0; //上个文字的右侧
                        ArrayList<Calendar> timeCache = new ArrayList<Calendar>(); //保存日期的缓存
                        ArrayList<Integer> yearTextLeftCache = new ArrayList<Integer>(); //绘制年文字的左侧位置缓存
                        ArrayList<Integer> yearTextRightCache = new ArrayList<Integer>(); //绘制年文字的右侧位置缓存
                        int textPadding = 5; //两个文字之间的最小间隔
                        //逐步递增索引，先绘制年
                        int bBottom = getHeight();
                        while (i <= lIndex)
                        {
                            Calendar dateObj = FCTran.numToDate(dates.get(i - fIndex));
                            timeCache.add(dateObj);
                            int year = dateObj.get(Calendar.YEAR); //从结构中获取年份
                            int x = getChartX(i); //获取索引对应的位置
//                            判断是否换年，以及是否在绘图区间内
                            if (year != lastYear && x >= drawLeft && x < size.cx - m_rightVScaleWidth)
                            {
                                int month = dateObj.get(Calendar.MONTH) + 1; //获取月的结构
                                String xText = new Integer(year).toString(); //拼接要绘制的文字
                                FCSize tSize = paint.textSize(xText, getFont(), -1); //计算要绘制文字的大小
                                //判断是否和上个文字重影
                                int tLeft = x + 2;
                                if (tLeft > lastTextRight)
                                {
                                    paint.drawLine(m_scaleColor, 1, 0, x, bBottom - m_hScaleHeight, x, bBottom); //绘制刻度线
                                    FCDraw.drawText(paint, xText, newScaleColor, getFont(), tLeft, bBottom - (m_hScaleHeight + tSize.cy) / 2); //绘制文字
                                    yearTextLeftCache.add(tLeft); //将年文字的左侧位置缓存
                                    yearTextRightCache.add(tLeft + tSize.cx + 5); //将年文字的右侧位置缓存
                                    drawYearsCache.add(year); //缓存要绘制的年
                                    lastTextRight = tLeft + tSize.cx + 5; //缓存上个文字的右侧位置
                                    lastYear = year; //记录上次绘制的年份
                                }
                            }
                            i = i + 1;	//索引累加
                        }
                        if (m_myChart.m_cycle <= 1440)
                        {
                            //绘制月份
                            for (int m = 0; m < drawYearsCache.size(); m++)
                            {
                                int cacheYear = drawYearsCache.get(m); //从缓存中获取年份
                                int lastMonth = 0; //缓存月份，用于判断是否换月
                                i = m_firstVisibleIndex; //重置开始索引
                                lastTextRight = 0; //重置上个文字的右侧
                                //逐步递增索引
                                while (i <= lIndex)
                                {
                                    Calendar dateObj = timeCache.get(i - m_firstVisibleIndex); //从缓存中获取time
                                    int year = dateObj.get(Calendar.YEAR); //从结构中获取年份
                                    //判断是否同一年
                                    if (cacheYear == year)
                                    {
                                        int month = dateObj.get(Calendar.MONTH) + 1; //从结构中获取月份
                                        int x = getChartX(i);
                                        //判断是否换月，以及是否在绘图区间内
                                        if (lastMonth != month && x >= drawLeft && x < size.cx - m_rightVScaleWidth)
                                        {
                                            String xText = new Integer(month).toString(); //获取绘制的月份文字
                                            if (xText.length() == 1)
                                            {
                                                xText = "0" + xText;
                                            }
                                            FCSize tSize = paint.textSize(xText, getFont(), -1); //计算要绘制文字的大小
                                            //判断是否和上个文字重影
                                            if (x > lastTextRight + textPadding)
                                            {
                                                if ((x > yearTextRightCache.get(m) + textPadding)
                                                        && ((m == drawYearsCache.size() - 1)
                                                        || ((m < drawYearsCache.size() - 1)
                                                        && (x + tSize.cx < yearTextLeftCache.get(m + 1) - textPadding))))
                                                {
                                                    paint.drawLine(m_scaleColor, 1, 0, x, bBottom - m_hScaleHeight, x, bBottom - m_hScaleHeight + 12); //绘制刻度
                                                    FCDraw.drawText(paint, xText, newScaleColor, getFont(), x + 2, bBottom - (m_hScaleHeight + tSize.cy) / 2); //绘制文字
                                                    lastTextRight = x + tSize.cx + 2; //缓存上个文字的右侧位置
                                                }
                                            }
                                            lastMonth = month; //记录上次绘制的月份
                                        }
                                    }
                                    else if (cacheYear < year)
                                    {
                                        break; //超过区间，退出循环
                                    }
                                    i = i + 1;	//索引累加
                                }
                            }
                        }
                    }
                }
                else
                {
                    int fIndex = m_firstVisibleIndex;
                    int lIndex = m_lastVisibleIndex;
                    if (lIndex >= fIndex)
                    {
                        Calendar lastDate2 = FCTran.numToDate(0);
                        ArrayList<Double> dates = new ArrayList<Double>();
                        for (int d = fIndex; d <= lIndex; d++)
                        {
                            dates.add(m_datas.get(d).m_date);
                        }
                        for (int i = fIndex; i <= lIndex; i++)
                        {
                            double dateNum = dates.get(i - fIndex);
                            String xText = new Double(dateNum).toString();
                            Calendar dt = FCTran.numToDate(dateNum);
                            Calendar dText = new GregorianCalendar(dt.get(Calendar.YEAR), dt.get(Calendar.MONTH + 1), dt.get(Calendar.DAY_OF_MONTH));
                            if (dText.get(Calendar.YEAR) != lastDate2.get(Calendar.YEAR))
                            {
                                SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                                xText = format.format(dt.getTime());
//                                xText = dt.toString("yyyy/MM/dd");
                            }
                            else
                            {
                                SimpleDateFormat format = new SimpleDateFormat("HH:mm");
                                xText = format.format(dt.getTime());
//                                xText = dt.toString("MM/dd");
                            }
                            if (!dText.equals(lastDate2))
                            {
                                lastDate2 = dText;
                                FCSize tSize = paint.textSize(xText, getFont(), -1);
                                int x = getChartX(i);
                                int dx = x + 2;
                                if (dx > dLeft && dx + tSize.cx < size.cx - m_rightVScaleWidth - 5)
                                {
                                    int bBottom = getHeight();
                                    paint.drawLine(m_scaleColor, m_lineWidthChart, 0, x, bBottom - m_hScaleHeight, x, bBottom - m_hScaleHeight + 12);
                                    paint.drawText(xText, newScaleColor, getFont(), new FCRect(dx, bBottom - (m_hScaleHeight + tSize.cy) / 2, dx + tSize.cx, bBottom - (m_hScaleHeight + tSize.cy) / 2), -1);
                                    i = i + (int)((tSize.cx + m_hScaleTextDistance) / m_hScalePixel) + 1;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public int getChartIndexReal(FCPoint mp)
    {
        if (m_datas.size() == 0)
        {
            return -1;
        }
        if (mp.x <= 0)
        {
            return 0;
        }
        double intX = mp.x - m_leftVScaleWidth - m_hScalePixel - m_offsetX;
        if (intX < 0)
        {
            intX = 0;
        }
        int index = (int)(m_firstVisibleIndex + intX / m_hScalePixel);
        int intPixel = (int)m_hScalePixel;
        if (intPixel > 0 && intX % intPixel != 0)
        {
            index++;
        }
        return index;
    }

    public void onPaint(FCPaint paint, FCRect clipRect)
    {
        super.onPaint(paint, clipRect);
        int cycle = m_myChart.m_cycle;
        String sName = "";
        if (cycle == 0)
        {
            sName = "实时";
        }
        else if (cycle < 1440)
        {
            sName = FCTran.intToStr(cycle) + "分";
        }
        else if (cycle == 1440)
        {
            sName = "日线";
        }
        else if (cycle == 10080)
        {
            sName = "周线";
        }
        else if (cycle == 43200)
        {
            sName = "月线";
        }
        else if (cycle == 129600)
        {
            sName = "季线";
        }
        else if (cycle == 259200)
        {
            sName = "半年线";
        }
        else if (cycle == 518400)
        {
            sName = "年线";
        }
        if (sName.length() > 0)
        {
            FCFont font = getFont();
            FCSize tSize = paint.textSize(sName, font, -1);
            int width = getWidth(), height = getHeight();
            int tX = width - m_rightVScaleWidth / 2 - tSize.cx / 2;
            int tY = getHeight() - m_hScaleHeight / 2 - tSize.cy / 2;
            if (MyColor.m_style == 0)
            {
                FCDraw.drawText(paint, sName, FCColor.rgb(249, 237, 6), font, tX, tY);
            }
            else
            {
                FCDraw.drawText(paint, sName, FCColor.Text, font, tX, tY);
            }
        }
        if (m_touchFactor != null)
        {
            int x = getChartX(m_sIndex);
            int candleDivHeight = getCandleDivHeight();
            ArrayList<String> strs = new ArrayList<String>();
            strs.add("权息变动");
            SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
            String xText = format.format(FCTran.numToDate(m_touchFactor.dwDate).getTime());
            strs.add("除权除息:" + xText);
            if (m_touchFactor.f1 > 0)
            {
                strs.add("每10股派现金" + FCTran.floatToStr(m_touchFactor.f1) + "元");
            }
            if (m_touchFactor.f3 > 0)
            {
                strs.add("每10股送股" + FCTran.floatToStr(m_touchFactor.f1) + "股");
            }
            if (m_touchFactor.f4 > 0)
            {
                strs.add("每10股配股" + FCTran.floatToStr(m_touchFactor.f1) + "元");
            }
            FCRect sRect = new FCRect(x, candleDivHeight, x + 150, candleDivHeight + strs.size() * 20);
            if (sRect.bottom > getHeight())
            {
                int sHeight = sRect.bottom - sRect.top;
                sRect.top = candleDivHeight - sHeight - 20;
                sRect.bottom = sRect.top + sHeight;
            }
            paint.fillRect(FCColor.Back, sRect);
            paint.drawRect(FCColor.Border, 1, 0, sRect);
            for (int i = 0; i < strs.size(); i++)
            {
                String str = strs.get(i);
                FCDraw.drawText(paint, str, getTextColor(), getFont(), sRect.left + 3, sRect.top + 2 + i * 20);
            }
        }
        if (m_floatStrs.size() > 0 && m_tick == 0)
        {
            int rowHeight = 18;
            FCFont font = new FCFont("Default", 13, false, false, false);
            FCPoint mp = getTouchPoint();
            int tWidth = 0;
            for (int i = 0; i < m_floatStrs.size(); i++)
            {
                String str = m_floatStrs.get(i);
                FCSize tSize = paint.textSize(str, font, -1);
                if (tWidth < tSize.cx)
                {
                    tWidth = tSize.cx;
                }
            }
            FCRect sRect = new FCRect(mp.x + 15, mp.y, mp.x + tWidth + 30, mp.y + m_floatStrs.size() * rowHeight + 10);
            int sWidth = sRect.right - sRect.left;
            int sHeight = sRect.bottom - sRect.top;
            if (sRect.bottom > getSize().cy)
            {
                sRect.top = 20;
                sRect.bottom = sRect.top + sHeight;
            }
            else if (sRect.top < 0)
            {
                sRect.top = 0;
                sRect.bottom = sHeight;
            }
            if (sRect.right > getWidth())
            {
                sRect.left = getWidth() - sWidth;
                sRect.right = sRect.left + sWidth;
            }
            if (MyColor.m_style == 0)
            {
                m_native.getPaint().fillRect(FCColor.rgba(0, 0, 0, 150), sRect);
            }
            else
            {
                m_native.getPaint().fillRect(FCColor.rgba(255, 255, 255, 150), sRect);
            }
            m_native.getPaint().drawRect(MyColor.USERCOLOR104, 1, 0, sRect);
            for (int i = 0; i < m_floatStrs.size(); i++)
            {
                String str = m_floatStrs.get(i);
                FCDraw.drawText(m_native.getPaint(), str, FCColor.Text, font, sRect.left + 5, sRect.top + rowHeight * i + 3);
            }
        }
    }

    public FCMenu m_menu = null;

    public void onTouchDown(FCTouchInfo touchInfo)
    {
        callTouchEvents(FCEventID.TouchDown, touchInfo);
        if (touchInfo.m_firstTouch)
        {
            FCPoint mp = touchInfo.m_firstPoint;
            m_resizeDiv = false;
            if (m_volDivPercent > 0)
            {
                int candleDivHeight = getCandleDivHeight();
                int hScalePos = candleDivHeight;
                if (mp.y >= hScalePos - 3 && mp.y <= hScalePos + 3)
                {
                    m_resizeDiv = true;
                }
            }
            if (!m_resizeDiv)
            {
                touchDownChart(touchInfo.m_firstTouch, touchInfo.m_firstPoint, touchInfo.m_secondTouch, touchInfo.m_secondPoint, touchInfo.m_clicks);
            }
        }
        invalidate();
    }

    public int m_timerID;

    public int m_tick;

    public void onTimer(int timerID)
    {
        super.onTimer(timerID);
        if (m_tick > 0)
        {
            m_tick--;
            if (m_tick == 0)
            {
                stopTimer(m_timerID);
                invalidate();
            }
        }
    }

    public void onTouchMove(FCTouchInfo touchInfo)
    {
        callTouchEvents(FCEventID.TouchMove, touchInfo);
        m_floatStrs.clear();
        stopTimer(m_timerID);
        m_tick = 0;
        FCPoint mp = touchInfo.m_firstPoint;
        if (m_volDivPercent > 0)
        {
            int candleDivHeight = getCandleDivHeight();
            int hScalePos = candleDivHeight;
            if (m_resizeDiv || (mp.y >= hScalePos - 3 && mp.y <= hScalePos + 3))
            {
                setCursor(FCCursors.SizeNS);
            }
            else
            {
                setCursor(FCCursors.Arrow);
            }
        }
        if (m_resizeDiv)
        {
            int contentHeight = (getHeight() - m_hScaleHeight);
            if (contentHeight > 0)
            {
                double rate = (double)mp.y / contentHeight;
                if (rate >= 0.1 && rate <= 0.9)
                {
                    m_candleDivPercent = rate;
                    m_volDivPercent = 1 - rate;
                    invalidate();
                }
            }
        }
        else
        {
            touchMoveChart(touchInfo.m_firstTouch, touchInfo.m_firstPoint, touchInfo.m_secondTouch, touchInfo.m_secondPoint);
            if (m_datas.size() > 0 && !(m_cycle.equals("trend")))
            {
                int crossStopIndex = getChartIndexReal(touchInfo.m_firstPoint);
                if (crossStopIndex >= 0 && crossStopIndex <= m_lastVisibleIndex && crossStopIndex < m_datas.size())
                {
                    SecurityData securityData = m_datas.get(crossStopIndex);
                    int highY = getChartY(0, securityData.m_high);
                    int lowY = getChartY(0, securityData.m_low);
                    if (mp.y >= Math.min(highY, lowY) - 5 && mp.y <= Math.max(highY, lowY) + 5)
                    {
                        double lastClose = securityData.m_close;
                        if (crossStopIndex > 0)
                        {
                            lastClose = m_datas.get(crossStopIndex - 1).m_close;
                        }
                        FCFont tFont = new FCFont("Default", 12f);
                        Security security = new Security();
                        ArrayList<String> strs = new ArrayList<String>();
                        if (securityData.m_startDate > 0 && securityData.m_endDate > 0)
                        {
                            Calendar startDate = FCTran.numToDate(securityData.m_startDate);
                            Calendar endDate = FCTran.numToDate(securityData.m_endDate);
                            int dayOfWeek1 = StockService.dayOfWeek(startDate.get(Calendar.YEAR), startDate.get(Calendar.MONTH) + 1, startDate.get(Calendar.DAY_OF_MONTH));
                            int dayOfWeek2 = StockService.dayOfWeek(endDate.get(Calendar.YEAR), endDate.get(Calendar.MONTH) + 1, endDate.get(Calendar.DAY_OF_MONTH));
                            String strWeek1 = getWeekStr(dayOfWeek1);
                            String strWeek2 = getWeekStr(dayOfWeek2);
                            SimpleDateFormat format = new SimpleDateFormat(m_hScaleFormat);
                            String strDate1 = format.format(startDate.getTime());
//                            String strDate1 = startDate.toString(m_hScaleFormat);
                            if (m_myChart.m_cycle >= 1440)
                            {
                                SimpleDateFormat forma = new SimpleDateFormat("yyyy/MM/dd");
                                strDate1 = forma.format(startDate.getTime());
//                                strDate1 = startDate.toString("yyyy/MM/dd");
                            }
                            else
                            {
                                SimpleDateFormat forma = new SimpleDateFormat("yyyy/MM/dd HH:mm");
                                strDate1 = forma.format(startDate.getTime());
//                                strDate1 = startDate.toString("yyyy/MM/dd HH:mm");
                            }
                            SimpleDateFormat forma = new SimpleDateFormat(m_hScaleFormat);
                            String strDate2 = forma.format(endDate.getTime());
//                            String strDate2 = endDate.toString(m_hScaleFormat);
                            if (m_myChart.m_cycle >= 1440)
                            {
                                SimpleDateFormat form = new SimpleDateFormat("yyyy/MM/dd");
                                strDate2 = form.format(endDate.getTime());
//                                strDate2 = endDate.toString("yyyy/MM/dd");
                            }
                            else
                            {
                                SimpleDateFormat form = new SimpleDateFormat("yyyy/MM/dd HH:mm");
                                strDate2 = form.format(endDate.getTime());
//                                strDate2 = endDate.toString("yyyy/MM/dd HH:mm");
                            }
                            if (m_myChart.m_cycle >= 1440)
                            {
                                strs.add("起:" + strDate1 + "," + strWeek1);
                                strs.add("止:" + strDate2 + "," + strWeek2);
                            }
                            else
                            {
                                strs.add("起:" + strDate1);
                                strs.add("止:" + strDate2);
                            }
                        }
                        else
                        {
                            Calendar dateTime = FCTran.numToDate(securityData.m_date);
                            int dayOfWeek = StockService.dayOfWeek(dateTime.get(Calendar.YEAR), dateTime.get(Calendar.MONTH) + 1, dateTime.get(Calendar.DAY_OF_MONTH));
                            SimpleDateFormat form = new SimpleDateFormat(m_hScaleFormat);
                            String strDate = form.format(dateTime.getTime());
//                            String strDate = dateTime.toString(m_hScaleFormat);
                            if (m_myChart.m_cycle >= 1440)
                            {
                                SimpleDateFormat formt = new SimpleDateFormat("yyyy/MM/dd");
                                strDate = formt.format(dateTime.getTime());
//                                strDate = dateTime.toString("yyyy/MM/dd");
                            }
                            else
                            {
                                SimpleDateFormat formt = new SimpleDateFormat("yyyy/MM/dd HH:mm");
                                strDate = formt.format(dateTime.getTime());
//                                strDate = dateTime.toString("yyyy/MM/dd HH:mm");
                            }
                            String strWeek = getWeekStr(dayOfWeek);
                            if (m_myChart.m_cycle >= 1440)
                            {
                                strs.add(strDate + "," + strWeek);
                            }
                            else
                            {
                                strs.add(strDate);
                            }
                        }
                        strs.add("开:" + FCTran.getValueByDigit(securityData.m_open, 2));
                        strs.add("高:" + FCTran.getValueByDigit(securityData.m_high, 2));
                        strs.add("低:" + FCTran.getValueByDigit(securityData.m_low, 2));
                        strs.add("收:" + FCTran.getValueByDigit(securityData.m_close, 2));
                        strs.add("量:" + FCTran.getValueByDigit(securityData.m_volume / 100, 0) + "手");
                        strs.add("额:" + FCTran.getValueByDigit(securityData.m_amount / 10000, 0) + "万");
                        double rate = 0;
                        if (lastClose != 0)
                        {
                            rate = 100 * (securityData.m_close - lastClose) / lastClose;
                        }
                        strs.add("涨:" + FCTran.getValueByDigit(rate, 2) + "%");
                        double range = 0;
                        if (lastClose != 0)
                        {
                            range = 100 * (securityData.m_high - lastClose) / lastClose - 100 * (securityData.m_low - lastClose) / lastClose;
                        }
                        strs.add("振:" + FCTran.getValueByDigit(range, 2) + "%");
                        m_floatStrs = strs;
                        m_tick = 3;
                        startTimer(m_timerID, 100);
                    }
                }
            }
        }
        invalidate();
    }

    public void onTouchUp(FCTouchInfo touchInfo) {
        if (m_resizeDiv) {
            m_resizeDiv = false;
        }
    }

    public boolean m_resizeDiv = false;

    public MyChart m_myChart = null;

    public FCComboBox m_subComboBox = null;

    /*
     * 添加视图
     */
    public void onAdd()
    {
        super.onAdd();
        if (m_subComboBox == null)
        {
            m_subComboBox = new FCComboBox();
            addView(m_subComboBox);
            m_subComboBox.setVisible(false);
            m_subComboBox.setReadOnly(true);
            m_subComboBox.setFont(new FCFont("Default", 12f));
            m_subComboBox.setLineHeight(10);
            m_subComboBox.setBorderColor(FCColor.None);
            m_subComboBox.setText("不复权");
            m_subComboBox.setTextColor(FCColor.Text);
            ArrayList<String> subStrs = new ArrayList<String>();
            subStrs.add("前复权");
            subStrs.add("后复权");
            subStrs.add("不复权");
            for (int i = 0; i < subStrs.size(); i++)
            {
                FCMenuItem menuItem = new FCMenuItem();
                menuItem.setText(subStrs.get(i));
                menuItem.setBorderColor(FCColor.None);
                m_subComboBox.addItem(menuItem);
            }
            m_subComboBox.update();
            m_subComboBox.setSelectedIndex(0);
            m_subComboBox.getDropDownButton().setBorderColor(FCColor.None);
            m_subComboBox.getDropDownMenu().setMinimumSize(new FCSize(80, 60));
            m_subComboBox.addEvent(this, "onselectedindexchanged", this);
        }
    }

    public int m_keyDownTick = 0;

    public void onKeyUp(char key)
    {
        super.onKeyUp(key);
        m_keyDownTick = 0;
    }

    public int getSubScription()
    {
        int sIndex = m_subComboBox.getSelectedIndex();
        if (sIndex == 0)
        {
            return 1;
        }
        else if (sIndex == 1)
        {
            return 2;
        }
        else
        {
            return 0;
        }
    }

    public void callEvent(String eventName, Object sender, Object invoke)
    {
        if (m_myChart.m_cycle > 0)
        {
            m_myChart.m_lastPixel = m_hScalePixel;
        }
        m_myChart.searchSecurity(m_myChart.m_code, m_myChart.m_cycle);
    }

    public static String getWeekStr(int week)
    {
        switch (week)
        {
            case 0:
                return "一";
            case 1:
                return "二";
            case 2:
                return "三";
            case 3:
                return "四";
            case 4:
                return "五";
            case 5:
                return "六";
            default:
                return "日";
        }
    }
}
